Forum Replies Created
-
In reply to: How to show code in forum posts?
Yeah, it’s not totally reliable with all different kinds of characters. I took the code directly from bbPress without any real modification. One of these days I will take a closer look to see if I can improve the way it escapes special characters.
In reply to: How to show code in forum posts?The code in the pastebin is exactly what’s running on bp.org, so it definitely works. If there’s a problem, it might be a theme-related conflict.
Make sure that you’re only using backticks, not [ code ]
In reply to: How to show code in forum posts?It looks like some of the escaped characters got stripped. Here’s what it’s supposed to look like: http://pastebin.com/Mvyc8TYx
Has anyone opened a Trac ticket for this issue? It’s more likely to get dedicated developer attention over there.
Awesome, good to know – I’ll have a more proper fix for the plugin sometime soon, but this will definitely work as a stopgap.
Can I get a bit of clarification on what “can’t” means in “users can’t upload”? Does it mean that the upload field isn’t showing up at all for non-admins? Or does it mean that they get an error when they do try uploading?
If it’s the former, try pasting the following lines into the very beginning of forum-attachments-for-buddypress-bp-functions.php, right after `<?php`:
`add_action(‘groups_forum_new_topic_after’,’bb_attachments_upload_form’);
add_action(‘groups_forum_new_reply_after’, ‘bb_attachments_upload_form’);
add_action(‘groups_forum_edit_post_after’, ‘bb_attachments_upload_form’);
add_action(‘bp_after_group_forum_post_new’, ‘bb_attachments_upload_form’);
add_action(‘bp_group_after_edit_forum_post’, ‘bb_attachments_upload_form’);`In reply to: “Create a Blog” Initial MessageNo, it looks like there’s no way to do it. It shouldn’t be that way, though – would you mind filing an enhancement ticket at trac.buddypress.org?
In reply to: bb_attachments roles for uploadingYour wish is my command

Actually, you should try setting them all to ‘read’. It’ll still be limited to logged in users in virtue of the fact that BP itself only allows members to post in forums.
I’m not near a computer at the moment, but I’ll try to figure it the problem as soon as I can.
In reply to: Getting rid of Gravatars …Cool, I’m glad the first part worked!
Here’s a thrown-together-in-five-minutes filter to replace missing avatars with BP’s default mystery man. This probably won’t differentiate between user and group avatars, which you’ll have to sniff out of the $params array (in sort of the same way that I do with width and height). The basic idea is: if bp_core_fetch_avatar is not outputting any HTML, swap out the boolean false with the default mystery man.
`function bbg_no_avatar( $html, $params ) {
if ( !$html ) {
if ( $params )
$height = ‘ height=”‘ . $params . ‘”‘;if ( $params )
$height = ‘ width=”‘ . $params . ‘”‘;$default_image_url = WP_PLUGIN_URL . ‘/buddypress/bp-core/images/mystery-man.jpg’;
$html = ‘‘;
}return $html;
}
add_action( ‘bp_core_fetch_avatar’, ‘bbg_no_avatar’, 10, 2 );`In reply to: bb_attachments roles for uploadingI think that ‘read’ is what you’re looking for, though I must admit that I haven’t put much thought into the way that the bbPress permissions translate in BP. That part of the plugin could use some real adaptation to BuddyPress, so that it uses things like `groups_is_user_mod()` rather than `bb_current_user_can()` – or at least a more consistent mapping of BP group permissions to bbPress.
In reply to: How to show code in forum posts?Here’s the code that does it on buddypress.org. It’s basically repurposed from bbPress.
I had to replace the actual backtick with the phrase `[backtick]` so that it would render properly on this forum. Make sure to correct that in your version.
`// Borrowed from bbPress
function bporg_encodeit( $matches ) {
$text = trim($matches[2]);
$text = htmlspecialchars($text, ENT_QUOTES);
$text = str_replace(array(“rn”, “r”), “n”, $text);
$text = preg_replace(“|nnn+|”, “nn”, $text);
$text = str_replace(‘&’, ‘&’, $text);
$text = str_replace(‘<', '<', $text);
$text = str_replace(‘>’, ‘>’, $text);
$text = “$text“;
if ( “[backtick]” != $matches[1] )
$text = “$text
“;
return $text;
}// Borrowed from bbPress
function bporg_decodeit( $matches ) {
$text = $matches[2];
$trans_table = array_flip(get_html_translation_table(HTML_ENTITIES));
$text = strtr($text, $trans_table);
$text = str_replace(‘
‘, ”, $text);
$text = str_replace(‘‘, ”, $text);
$text = str_replace(‘‘, ”, $text);
$text = str_replace(array(‘&’,’&’), ‘&’, $text);
$text = str_replace(”’, “‘”, $text);
if ( ‘' == $matches[1] )
$text = "n$textn";
return "`$text`";
}
// Borrowed from bbPress. Makes code in backticks work, both in forum posts and in activity updates.
function bporg_code_trick( $text ) {
$text = str_replace(array("rn", "r"), "n", $text);
$text = preg_replace_callback("|(`)(.*?)`|", 'bporg_encodeit', $text);
$text = preg_replace_callback("!(^|n)`(.*?)`!s", 'bporg_encodeit', $text);
return $text;
}
add_filter( 'bp_get_the_topic_post_content', 'bporg_code_trick', 1 );
add_filter( 'bp_get_activity_content_body', 'bporg_code_trick', 1 );`In reply to: Custom CSS ChangesAre you sure that your custom-sample.css file is actually being included? With a file name like ‘custom-sample’, I’m guessing that it might not be. Check out the theme’s main style.css, and see if there’s an @import rule for custom-sample.css (or if there is a rule in any other imported stylesheet).
I’m not sure how bp-social works (it appears to be a premium theme so I can’t look at the code) but if it is a child of bp-default, then you won’t be able to create a “grandchild” theme so that your changes won’t be overridden – WP doesn’t support that. However, you could fake it by dropping a snippet in your bp-custom.php file that looks something like this:
`function bbg_custom_style() {
$myStyleUrl = WP_PLUGIN_URL . ‘/custom.css’;
$myStyleFile = WP_PLUGIN_DIR . ‘/custom.css’;
if ( file_exists($myStyleFile) ) {
wp_register_style(‘myStyleSheet’, $myStyleUrl);
wp_enqueue_style( ‘myStyleSheet’);
}
}
add_action(‘wp_print_styles’, ‘bbg_custom_style’);`(See https://codex.wordpress.org/Function_Reference/wp_enqueue_style for more info on how to enqueue styles)
Just make sure that you have your custom styles in a file called custom.css in your plugin directory. That should make sure that your styles get loaded, but that they don’t get overwritten by future upgrades to your main theme.
`groups_is_user_mod( $user_id, $group_id )`
`groups_is_user_admin( $user_id, $group_id )`Check out their definitions in bp-groups.php. They check whether the user is a mod/admin of a particular group.
But that won’t work all that well on a profile page, because a user could be a member of a number of groups, so you won’t have a specific group_id to feed into the function. In what circumstances will the Moderator button appear? If they’re a moderator of *any* groups?
In reply to: Detecting User ID of a poster of a forum topicTry bp_get_the_topic_poster_id().
bp-forums-templatetags.php has all of those functions. If there isn’t a template tag for the data you need, make your own – you can use those as a pattern (getting the value out of an appropriate global).
In reply to: Reply to forums through EmailI would love this, and it’s something I’ve thought of building myself. I’ve been waiting, hoping that the rumored post/comment-by-email core WP plugin would materialize and provide a foundation on which to build the BP functionality.
I’ll poke around to see if I can find a good starting place. If anyone else finds anything, be sure to share.
In reply to: Getting rid of Gravatars …At the moment, there is no easy way to turn off Gravatar. I agree that there should be an easy way, as there can be performance concerns, as @mistercyril. (Though I find “I’m starting to think I’m the only one concerned with performance” unnecessarily confrontational.) I’ve had issues with it in the past myself.
I’ve just opened a ticket to make disabling Gravatar easier: https://trac.buddypress.org/ticket/2697 Until it’s been implemented, here’s the general core-hack strategy for disabling Gravatar altogether:
1) In bp-core/bp-core-avatars.php, find where the $defaults for bp_core_fetch_avatar() are set. Change
`’no_grav’ => false,`
to
`’no_grav’ => true,`2) There will likely be some instances where the Mystery Man doesn’t kick in properly (group avatars, existing users). Write a filter for `’bp_core_fetch_avatar’` that sets the avatar to some default value when no avatar is returned.
jquery should already be loaded on all Dashboard panels, I think. You may still need to load jquery-ui. In that case, your method looks like it should work. The only possible snag I can see is that is_admin() might return false until after the ‘init’ action. In that case, try just doing
`add_action(‘init’, ‘load_js’);`
and move the admin check inside of the load_js() function:
`function load_js() {
if ( !is_admin() )
return false;
wp_register_script….`Here’s how buddypress.org does it, with a filter that essentially adds a search term ‘@username‘ to the bp_has_activities filter:
`function bporg_activity_with_others_filter( $qs ) {
global $bp;$user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
/* Only filter on directory pages (no action) and the following scope on activity object. */
if ( ( ‘dashboard’ == $bp->current_action && strpos( $qs, ‘personal’ ) !== false ) || ‘just-me’ == $bp->current_action ) {
if ( strpos( $qs, ‘filter’ ) === false )
$qs .= ‘&search_terms=@’ . bp_core_get_username( $user_id ) . ‘<';return $qs;
} else {
return $qs;
}
}
add_filter( ‘bp_ajax_querystring’, ‘bporg_activity_with_others_filter’, 11 );`The problem with this approach is that the search bypasses the private/hidden group setting, so activity created inside of a group will show up on public profile pages if it contains @username in it. Here’s a filter that gets around it about halfway, in a hackish way:
`function bporg_ensure_hidden_activity_updates( $has_activities ) {
global $activities_template, $bp;if ( bp_is_my_profile() || !$bp->displayed_user->id )
return $has_activities;foreach( $activities_template->activities as $a_key => $a ) {
if ( $a->type != ‘activity_update’ && $a->type != ‘activity_comment’ )
continue;if ( $a->component != ‘groups’ )
continue;$group = new BP_Groups_Group( $a->item_id );
if ( $group->status != ‘public’ ) {
unset( $activities_template->activities[$a_key] );
$activities_template->total_activity_count = $activities_template->total_activity_count – 1;
$activities_template->activity_count = $activities_template->activity_count – 1;
}$activities_template->activities = array_values( $activities_template->activities );
}return $has_activities;
}
add_filter( ‘bp_has_activities’, ‘bporg_ensure_hidden_activity_updates’, 999 );`This latter problem should be fixed in BP 1.3.
Ping @djpaul
In reply to: Change another user’s avatarHeh heh. I was looking for “change avatar” under the edit profile section. Dang wording threw me off
In reply to: Change another user’s avatarActually, you should be able to do this out of the box, there’s just no link for it. To change a user’s avatar, visit the link
http://[example.com]/members/%5Bmembername%5D/profile/change-avatarIn reply to: Disable name change for usersTry this on for size. Hackish but functional, until real exclude arguments exist (they’re coming in 1.3, I promise!) Put it in your bp-custom.php
`function bbg_disallow_name_edit( $has_profile ) {
global $profile_template, $bp;if ( ‘edit’ != $bp->current_action || !bp_is_my_profile() )
return $has_profile;foreach( (array)$profile_template->groups as $group_key => $group ) {
foreach( (array)$group->fields as $field_key => $field ) {
if ( $field->name == BP_XPROFILE_FULLNAME_FIELD_NAME ) {
unset( $profile_template->groups[$group_key]->fields[$field_key] );
$profile_template->groups[$group_key]->fields = array_values(
$profile_template->groups[$group_key]->fields );
break 2;
}
}
}return $has_profile;
}
add_filter( ‘bp_has_profile’, ‘bbg_disallow_name_edit’ );`In reply to: New avatars after installing latest BP?Try dropping this in bp-custom.php:
`function bbg_remove_secondary_avatar() {
return false;
}
add_filter( ‘bp_get_activity_secondary_avatar’, ‘bbg_remove_secondary_avatar’ );`Are you using a custom theme?